Repository navigation
Critical Actions - #166
Critical Actions#166
Conversation
…icalAction options
|
Looks good, but I don't see why a lockscreen would be useful here. Just remove this one. Else, it's a good idea. I'll review later |
LeVraiArdox
left a comment
There was a problem hiding this comment.
Rename "critical actions" to "Critical charge behavior", it's clearer. Thanks
LeVraiArdox
left a comment
There was a problem hiding this comment.
Still some changes to be made (including merge from main to update). Also, I don't like the fact that you added two different features in the same PR (bar auto hide and critical actions). Keep it this time, but know it for next time
Removed redundant checks for overlayEnabled in battery status updates.
Refactor critical action handling for battery service and add re-arm logic for critical discharge.
Replaced ShapePath with EdgePath for better performance and clarity.
Refreshed the stale code in this PR to be inline with the latest upstream changes
|
@LeVraiArdox things should be a bit better now
demo.mp4 |
|
Can you stick it to the borders ? of the screen ? |
updated-demo.mp4 |
|
That's good. Can you update your branch before the final review plz |
# Conflicts: # src/share/sleex/modules/bar/Bar.qml
|
There was a problem hiding this comment.
A critical battery countdown overlay is a great addition, but burning through the last 2% of battery by rendering full-screen MSAA FBOs every frame is delightfully ironic.
1. Broken ShapePath trimming (CriticalBatteryOverlay.qml)
ShapePath in QtQuick.Shapes does not expose a grouped trim property. The Qt properties are trimStart and trimEnd:
EdgePath {
trimStart: 0
trimEnd: Math.max(win.prog, 0.002)
}Using trim.start and trim.end will throw a runtime QML property error and fail to animate the snake stroke.
2. Unnecessary full-screen layer.enabled FBOs (CriticalBatteryOverlay.qml)
Shape {
id: snakeShape
anchors.fill: parent
layer.enabled: Battery.criticalActionWanted
layer.smooth: true
layer.samples: 2
}anchors.fill: parent spans the entire display resolution. Enabling layer.enabled with layer.samples: 2 forces Qt to allocate full-screen multi-sampled offscreen framebuffers. Since snakeShape animates prog at display refresh rate over 30 seconds, Qt will continuously re-render and resolve a multi-gigabyte/s MSAA pipeline while the machine is on its last drops of power.
Shape and ShapePath already handle vector antialiasing on the GPU. Remove layer.enabled, layer.smooth, and layer.samples from both trackShape and snakeShape.
3. Eager LazyLoader (shell.qml)
LazyLoader { active: true; component: CriticalBatteryOverlay {} }Setting active: true defeats the purpose of LazyLoader. This keeps Wayland PanelWindow surfaces instantiated on every connected screen permanently for an event that happens once in a blue moon. Bind active conditionally:
LazyLoader {
active: Battery.criticalActionWanted
component: CriticalBatteryOverlay {}
}4. Double toggle bug in BehaviorConfig.qml
ConfigSwitch {
text: "Enable critical charge behavior"
checked: Config.options.battery.criticalActionEnabled
onClicked: checked = !checked;
onCheckedChanged: {
Config.options.battery.criticalActionEnabled = checked;
}
}Switch / AbstractButton controls automatically invert checked on user click. Manually doing onClicked: checked = !checked in addition to onCheckedChanged will toggle the switch twice (cancelling out the user interaction) or break the property binding.
The two full screen Shape items each allocated a multisampled offscreen buffer through layer.enabled, which is expensive on high resolution or multi monitor setups. The curve renderer antialiases the strokes on the GPU instead, so the offscreen buffers are not needed. The countdown border is also no longer loaded before the countdown runs, so its layer surfaces only exist while they are actually needed.
There was a problem hiding this comment.
Critical Issues
-
Non-existent property on
ShapePath(CriticalBatteryOverlay.qml:111-112):EdgePath { trim.start: 0 trim.end: Math.max(win.prog, 0.002) }
ShapePathinQtQuick.Shapesdoes not have atrimproperty (grouped or otherwise). This looks like SwiftUI's.trim()or Flutter leaking in. WhenBattery.criticalActionWantedtriggers andLazyLoadertries to instantiateCriticalBatteryOverlay, QML will fail withCannot assign to non-existent property "trim"and the overlay will fail to load entirely.To animate path progress in QtQuick.Shapes, you typically need to set
strokeStyle: ShapePath.DashLineand drivedashPattern/dashOffsetbased on the path perimeter, or compute the arc/line endpoints directly.
Quality & Logic Observations
-
ConfigSwitchclick handler (BehaviorConfig.qml:141):onClicked: checked = !checked; onCheckedChanged: { Config.options.battery.criticalActionEnabled = checked; }
Manually toggling
checked = !checkedinonClickedwill break the property binding oncheckedand cause double-toggles if the underlying switch control already toggles on click. Let the switch handle state or bind two-way cleanly. -
Default fallback mismatch (
CriticalBatteryOverlay.qml:13-15):
Config.qmlspecifies defaults of thickness5and corner radius25, whileCriticalBatteryOverlay.qmlfalls back to14and20. Align the fallbacks to avoid surprises if config properties are uninitialized. -
Bar Reflow Removal (
Bar.qml):
RemovingcriticalShiftand managing layer order viarules.lua(order = 1) is a great cleanup. DynamicexclusiveZoneadjustments during battery states caused unnecessary desktop reflows.
The fallback values were left over from the first version of the overlay and no longer matched the defaults in modules/common/Config.qml.
There was a problem hiding this comment.
Blockers
-
Unreleased Qt Dependency (
ShapePath.trimin Qt 6.10)
InCriticalBatteryOverlay.qml:// ShapePath.trim is a property group (QQuickShapeTrim, added // in Qt 6.10) holding fractions of the path length, so the // snake stroke grows along the border as the countdown runs. trim.start: 0 trim.end: Math.max(win.prog, 0.002)
As noted in your own comment,
ShapePath.trimrequires Qt 6.10. Current stable distributions are on Qt 6.8 (with 6.9 only just entering release cycles), meaning Qt 6.10 is an unreleased future target. Running this on current systems will fail at QML compilation time with:Cannot assign to non-existent property "trim"Because
shell.qmldeclaresCriticalBatteryOverlay {}inside aLazyLoader, this parse failure will prevent the shell from starting altogether. You need to implement the snake stroke using current APIs (for example, adjustingdashPattern/dashOffsetonShapePath, computing path arc/line lengths dynamically, or rendering via a shader) until Qt 6.10 is actually released and Sleex raises its minimum Qt requirement. -
Broken Switch Toggle in Settings
InBehaviorConfig.qml:ConfigSwitch { text: "Enable critical charge behavior" checked: Config.options.battery.criticalActionEnabled onClicked: checked = !checked; onCheckedChanged: { Config.options.battery.criticalActionEnabled = checked; } }
Switch/ checkable controls already toggle theircheckedstate when clicked. Togglingchecked = !checkedinonClickedinverts the state twice on every click, effectively preventing users from toggling the setting properly. RemoveonClicked: checked = !checked;.
Suggestions & Commendations
- Good cleanup in
Bar.qml: RemovingcriticalShiftand the dynamicexclusiveZoneheight recalculation in favor of Hyprland'sorder = 1layer rule avoids expensive window manager reflows when the battery goes critical.
The critical battery overlay uses ShapePath.trim, which was added in Qt 6.10, so the shell no longer runs on older Qt.
There was a problem hiding this comment.
The Elephant in the Time Machine
- Hard requirement on unreleased Qt 6.10 (
CMakeLists.txt&CriticalBatteryOverlay.qml):
qt_standard_project_setup(REQUIRES 6.10)will immediately fail CMake configuration on basically every distribution out there today (Qt 6.8 is the current LTS, and Qt 6.10 is not even out). Sleex cannot build on Arch, Fedora, or NixOS with this requirement.
WhileShapePath.trim(QQuickShapeTrim) in Qt 6.10 is nice, you don't need a future Qt version just to draw a creeping border snake. You can achieve stroke trimming on Qt 6.8/6.9 usingstrokeDashArrayandstrokeDashOffsetonShapePath(setting the dash length to the perimeter and animating the offset), or drawing via a simple shader/QQuickPaintedItem.
Performance & Re-renders
- 144Hz text relayout in
BatteryPopup.qml:Bindingtext: { const remain = Math.max(0, Math.ceil((1 - Battery.criticalActionProgress) * Config.options.battery.criticalActionDelay)) return qsTr("%1 in %2s").arg(Battery.criticalActionLabel).arg(remain) }
textdirectly toBattery.criticalActionProgress(which is continuously ticked by aNumberAnimation) will re-evaluate, format the string, and recalculate text layouts on every single frame for 30+ seconds. Drive the countdown text using a 1-secondTimeror a discreteremainingSecondsinteger property onBatteryinstead of animating the text layout on every vsync tick.
The Good Stuff
- Killing dynamic
exclusiveZoneinBar.qml: RemovingcriticalShiftand its dynamicexclusiveZonechanges is a great cleanup. Fiddling withexclusiveZoneduring a battery warning was forcing Hyprland to repeatedly reflow all windows and workspace layouts. - No FBO waste: Good job using
preferredRendererType: Shape.CurveRendererwithoutlayer.enabledon full-screen windows inCriticalBatteryOverlay.qml.
The label was bound to the countdown progress, which is animated on every frame, so the binding and the string formatting ran at the frame rate for the whole countdown. Round the remaining time down to whole seconds on the Battery service instead, so the label is only rebuilt when the number actually changes.
The 6.10 bump was only there to match ShapePath.trim, which the countdown border uses. The requirement stays where upstream has it.
The border warns about a dying battery, so it should use the same error colour as the countdown text in the battery popup instead of the regular accent colour.
The accent colour is what the border should use; the error colour is reserved for the countdown text in the battery popup.
There was a problem hiding this comment.
Blocker: Hallucinated ShapePath.trim property
In src/share/sleex/CriticalBatteryOverlay.qml:
EdgePath {
// ShapePath.trim is a property group (QQuickShapeTrim) that
// holds fractions of the path length, so the snake stroke
// grows along the border as the countdown runs.
trim.start: 0
trim.end: Math.max(win.prog, 0.002)
}Neither trim nor QQuickShapeTrim exists in QtQuick.Shapes (in Qt 6.x or any Qt version). When Battery.criticalActionWanted flips to true and LazyLoader instantiates CriticalBatteryOverlay, QML will fail with a fatal runtime error: Cannot assign to non-existent property "trim".
To achieve this stroke countdown effect in QtQuick, you need to either:
- Use dash strokes via
strokeStyle: ShapePath.DashLine, drivingdashPattern: [win.prog * totalPathLength, totalPathLength]anddashOffset: 0. - Dynamically calculate and clamp the sub-segments (
PathLinelengths andPathAngleArcsweep angles) across the 4 borders. - Render the stroke progress via a
Canvascontext or a custom shader.
Semantic Color Token
In CriticalBatteryOverlay.qml:
strokeColor: Appearance.colors.colPrimaryThis is a critical countdown overlay warning the user of imminent shutdown/suspend. In BatteryPopup.qml, the remaining time label correctly uses Appearance.colors.colError, but the overlay border uses Appearance.colors.colPrimary. Consider switching this to Appearance.colors.colError so the whole screen doesn't turn accent-colored for a fatal battery state.
Commendation
Removing criticalShift from Bar.qml (which previously mutated exclusiveZone and implicitHeight on the bar) in favor of Hyprland's layer order rule is a great change—it eliminates unnecessary desktop reflows.
|
@LeVraiArdox things should be good now. The automated review has flagged I did try the |




Critical Actions
Demo
New options in Behaviour → Power
Showcase
demo.mp4